package com.kmxd.ams.core.util;

import com.baomidou.mybatisplus.core.toolkit.LambdaUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.support.LambdaMeta;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import org.apache.ibatis.reflection.property.PropertyNamer;

/**
 * 字段通用类
 *
 * @author nickbi
 */
public class FieldUtil {

  public static <T> String getColumn(SFunction<T, ?> column) {
    LambdaMeta meta = LambdaUtils.extract(column);
    String property = PropertyNamer.methodToProperty(meta.getImplMethodName());
    return StringUtils.camelToUnderline(property);
  }

  public static <T> String getFieldName(SFunction<T, ?> column) {
    LambdaMeta meta = LambdaUtils.extract(column);
    return PropertyNamer.methodToProperty(meta.getImplMethodName());
  }
}
